
-- procedure to add a new user
-- it returns 1 if can add, 0 cannot add

IF OBJECT_ID('addUser') IS NOT NULL	
BEGIN
	DROP PROCEDURE addUser;
END
GO
CREATE PROCEDURE addUser
	@FirstName		varchar(50),
	@LastName		varchar(50),
	@Gender			varchar(6),
	@Address		varchar(200),
	@UserName		varchar(30),
	@Password		varchar(50),
	@UserType		varchar(20)
AS
BEGIN
	IF NOT EXISTS(SELECT * FROM users WHERE username=@UserName)
	BEGIN
		INSERT INTO [users](firstname, lastname, gender, [address],username, [password], usertype)
		VALUES(@FirstName, @LastName, @Gender, @Address, @UserName, @Password, @UserType);
		SELECT 1;
	END
	ELSE
	BEGIN
		SELECT 0;
	END
END
GO
